package tr.gov.tubitak.bilgem.esya.crlviewer;

import sun.security.x509.X509CRLImpl;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.cert.CRLException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509CRL;
import java.util.logging.Level;

/**
 * Created by IntelliJ IDEA.
 * User: ramazan.girgin
 * Date: 4/17/12
 * Time: 4:19 PM
 * To change this template use File | Settings | File Templates.
 */
public class ECrlUtil {
    private static final String X509_CERT_TYPE = "X.509";
    static EViewerCRL loadCrl(byte[] crlValue){
        EViewerCRL retCrl = null;
        InputStream inputStream=null;
        URL url;
        try
        {
            X509CRLImpl crlImp=new X509CRLImpl(crlValue);
            retCrl =  new EViewerCRL(crlImp);
        }
        catch (Exception exc)
        {
            exc.printStackTrace();
        }
        finally
        {
            try
            {
                if(inputStream!=null)
                    inputStream.close();
            }
            catch (IOException e)
            {
                //LOG.log(Level.WARNING, "Could not close input stream from " + crlFilePath, e);
            }
        }
        return  retCrl;
    }

    static EViewerCRL loadCrl(String crlFilePath){
        /** Type name for X.509 certificates */
        EViewerCRL retCrl = null;
        InputStream inputStream=null;
        URL url;
        try
        {
            inputStream = new FileInputStream(crlFilePath);
            X509CRLImpl crlImp=new X509CRLImpl(inputStream);
            retCrl =  new EViewerCRL(crlImp);
        }
        catch (Exception exc)
        {
            exc.printStackTrace();
        }
         finally
        {
            try
            {
                if(inputStream!=null)
                    inputStream.close();
            }
            catch (IOException e)
            {
                //LOG.log(Level.WARNING, "Could not close input stream from " + crlFilePath, e);
            }
        }
            return  retCrl;
    }
}
